package com.parkingspace.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.parkingspace.entity.Complain;
import com.parkingspace.entity.Property;
import com.parkingspace.service.impl.ComplainServiceImpl;
import com.parkingspace.util.Constants;
import com.parkingspace.util.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 投诉表 前端控制器
 * </p>
 *
 * @author Gapper
 * @since 2021-05-24
 */
@RestController
@RequestMapping("/complain")
public class ComplainController {

    @Autowired
    private ComplainServiceImpl complainService;

    @GetMapping("/getComplainList")
    public ResultVO getComplainList(String token,Complain complain, Page page) {
        System.out.println("进来了+++++++（全查）"+complain);
        ResultVO resultVO;
        List<Complain> complainList;
        IPage pages= complainService.getComplainList(complain,page);
        System.out.println("111111111111111");
        System.out.println("recordes:"+pages.getRecords());
        System.out.println("222222222222222");
        if (token==null){
            return  null;
        }
        if (pages ==null){
            return new ResultVO(Constants.OPER_FAILURE,"查询失败1",pages);
        }
        return new ResultVO(Constants.OPER_SUCCESS,"成功",pages);
    }

    @PutMapping("/updComplainById")
    public ResultVO updComplainById(Complain complain) {
        System.out.println("进来了+++++++（全查）"+complain);
        ResultVO resultVO;

        boolean b = complainService.updComplainById(complain);
//        complainService.getComplainList(complain);



        if (b==false){
            return new ResultVO(Constants.OPER_FAILURE,"修改失败1",false);
        }
        return new ResultVO(Constants.OPER_SUCCESS,"修改成功",true);
    }

    @GetMapping("/getComplainById")
    public ResultVO getComplainById(Complain complain) {
        System.out.println("getComplainById(controller)进来了"+complain.getComplainId());
        ResultVO resultVO;
        Complain c=null;
        c=complainService.getComplainById(complain);

        if (c==null){
            return new ResultVO(Constants.OPER_FAILURE,"查询失败1",c);
        }
        return new ResultVO(Constants.OPER_SUCCESS,"成功",c);
    }

//    @GetMapping("/getAppraiseList")
//    public ResultVO getAppraiseList( ) {
//        System.out.println("进来了+++++++（全查）"+);
//        ResultVO resultVO;
//        List<Complain> propertyList;
//        List<Complain> complainList = complainService.getComplainList();



//        if (complainList.size() == 0){
//            return new ResultVO(Constants.OPER_FAILURE,"查询失败1",null);
//        }
//        return new ResultVO(Constants.OPER_SUCCESS,"成功",complainList);
//    }


}

